home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / misc / shellscr / src / paths.asm < prev    next >
Assembly Source File  |  1999-11-30  |  5KB  |  231 lines

  1. ; For copying DOS command paths
  2. ; Used in ShellScr by Kyzer/CSG
  3. ;
  4. ; Based on dospath.library source by Stefan Becker
  5. ; all functions withstand being passed NIL
  6.  
  7. call    macro
  8.     move.l    \2base(a4),a6
  9.     movem.l    a0/a1/d1,-(sp)
  10.     jsr    _LVO\1(a6)
  11.     movem.l    (sp)+,d1/a0/a1
  12.     endm
  13. clra    macro
  14.     suba.l    \1,\1
  15.     endm
  16. baddr    macro
  17.     add.l    \1,\1
  18.     add.l    \1,\1
  19.     endm
  20. mkbaddr    macro
  21.     asr.l    #2,\1
  22.     endm
  23.  
  24.     include    dos/dos.i
  25.     include    dos/dosextens.i
  26.     include    exec/memory.i
  27.     include    exec/nodes.i
  28.     include    exec/ports.i
  29.     include    exec/tasks.i
  30.     include    exec/types.i
  31.     include    lvo/dos_lib.i
  32.     include    lvo/exec_lib.i
  33.     include    workbench/startup.i
  34.  
  35.     include    eglobs.i
  36.  
  37.      STRUCTURE    PathList,0
  38.     BPTR    pl_next
  39.     BPTR    pl_lock
  40.     LABEL    pl_SIZEOF
  41.  
  42. ;------------------------------------------------------------------------------
  43. ; PTR TO commandlineinterface=getcli(PTR TO process) - private call
  44. ; d0=0 and Z flag set if not a process or no commandlineinterface
  45.  
  46. getcli    moveq    #0,d0
  47.     cmp.l    d0,a0
  48.     beq.s    .fail
  49.     cmp.b    #NT_PROCESS,LN_TYPE(a0)
  50.     bne.s    .fail
  51.     move.l    pr_CLI(a0),d0
  52.     baddr    d0
  53.     rts
  54. .fail    moveq    #0,d0
  55.     rts
  56.  
  57. ;------------------------------------------------------------------------------
  58. ; PTR TO pathlist=getpathlist(PTR TO process)
  59. ; returns a normal pointer to the initial pathlist entry of the process
  60.  
  61.     xdef    getpathlist__i
  62. getpathlist__i
  63.     move.l    4(sp),a0
  64. getpathlist
  65.     bsr.s    getcli
  66.     beq.s    .fail
  67.     move.l    d0,a0
  68.     move.l    cli_CommandDir(a0),d0
  69.     baddr    d0
  70. .fail    rts
  71.  
  72.  
  73. ;------------------------------------------------------------------------------
  74. ; BPTR TO pathlist=getpath()
  75. ; makes a clone of 'your' pathlist. NOTE: returns BPTR, not PTR
  76.  
  77.     xdef    getpath
  78. getpath    move.l    execbase(a4),a6
  79.     jsr    _LVOForbid(a6)
  80.     move.l    wbmessage(a4),d0    ; from eglobs.i
  81.     beq.s    .getslf
  82.     move.l    d0,a0
  83.     bsr.s    getwbtask
  84.     bra.s    .gottsk
  85. .getslf    suba.l    a1,a1
  86.     jsr    _LVOFindTask(a6)
  87. .gottsk    move.l    d0,a0
  88.     bsr.s    getpathlist
  89.     move.l    d0,a0
  90.     bsr.s    copypathlist
  91.     move.l    d0,-(sp)
  92.     move.l    execbase(a4),a6
  93.     jsr    _LVOPermit(a6)
  94.     move.l    (sp)+,d0
  95.     mkbaddr    d0
  96.     rts
  97.  
  98. ;------------------------------------------------------------------------------
  99. ; PTR TO process=getwbtask(PTR TO wbstartup)
  100. ; returns a pointer to the Workbench/Launcher's process
  101.  
  102.     xdef    getwbtask__i
  103. getwbtask__i
  104.     move.l    4(sp),a0
  105. getwbtask
  106.     move.l    MN_REPLYPORT(a0),d0
  107.     bne.s    .port
  108.     lea    .wbname(pc),a1
  109.     move.l    execbase(a4),a6
  110.     jmp    _LVOFindTask(a6)
  111. .port    move.l    d0,a0
  112.     move.l    MP_SIGTASK(a0),d0
  113.     rts
  114. .wbname    dc.b    'Workbench',0
  115.     even
  116.  
  117. ;------------------------------------------------------------------------------
  118. ; PTR TO pathlist=copypathlist(PTR TO pathlist)
  119. ; clone a pathlist
  120.  
  121. FROM    equr    A0
  122. CURRENT    equr    A1
  123. HEAD    equr    A2
  124. NEXT    equr    A3    ;
  125. ZERO    equr    D7    ; constant 0
  126.  
  127. tsta    macro
  128.     cmp.l    ZERO,\1
  129.     endm
  130.  
  131.     xdef    copypathlist__i
  132. copypathlist__i
  133.     move.l    4(sp),FROM
  134. copypathlist
  135.     movem.l    d7/a2/a3,-(sp)
  136.     clra    CURRENT
  137.     clra    HEAD
  138.     clra    NEXT
  139.     moveq    #0,d7
  140.  
  141. .again
  142.     tsta    FROM
  143.     beq.s    .end
  144.  
  145.     tsta    NEXT
  146.     bne.s    .gotmem
  147.  
  148.     moveq    #pl_SIZEOF,d0
  149.     moveq    #MEMF_PUBLIC,d1
  150.     call    AllocVec,exec
  151.     move.l    d0,NEXT    ; if (!NEXT) NEXT=AllocVec(sizeof(PathList), MEMF_PUBLIC)
  152.     
  153. .gotmem    tsta    NEXT    ; if (!NEXT) { freepathlist(HEAD); return NULL; }
  154.     bne.s    .got
  155.     move.l    HEAD,a0
  156.     bsr.s    freepathlist
  157.     moveq    #0,d0
  158.     rts
  159. .got
  160.     move.l    pl_lock(FROM),d1
  161.     call    DupLock,dos
  162.     move.l    d0,pl_lock(NEXT)
  163.     beq.s    .next
  164.     clr.l    pl_next(NEXT)
  165.  
  166.     tsta    HEAD
  167.     bne.s    .gothd
  168.     move.l    NEXT,HEAD    ; if (!HEAD) HEAD=NEXT
  169. .gothd
  170.  
  171.     tsta    CURRENT
  172.     beq.s    .nonext
  173.     move.l    NEXT,d0
  174.     mkbaddr    d0
  175.     move.l    d0,pl_next(CURRENT)
  176. .nonext    move.l    NEXT,CURRENT
  177.     clra    NEXT
  178.  
  179. .next    move.l    pl_next(FROM),FROM    ; FROM=BADDR(FROM.next)
  180.     baddr    FROM
  181.     bra.s    .again
  182.  
  183. .end    move.l    NEXT,a1
  184.     call    FreeVec,exec
  185.  
  186.     move.l    HEAD,d0        ; return HEAD
  187. .done    movem.l    (sp)+,d7/a2/a3
  188.     rts
  189.  
  190. ;------------------------------------------------------------------------------
  191. ; freepathlist(PTR TO pathlist)
  192. ; frees a pathlist - note it takes a normal pointer, not a BPTR
  193.  
  194.     xdef    freepathlist__i
  195. freepathlist__i
  196.     move.l    4(sp),a0
  197. freepathlist
  198. .again    move.l    a0,a1        ; current(a1) = next(a0)
  199.     moveq    #0,d0
  200.     cmp.l    d0,a1        ; end if current=0
  201.     beq.s    .done
  202.     move.l    pl_next(a1),a0    ; next=BADDR(current.next)
  203.     baddr    a0
  204.  
  205.     move.l    pl_lock(a1),d1
  206.     call    UnLock,dos    ; d1=current.lock
  207.     call    FreeVec,exec    ; a1=current
  208.  
  209.     bra.s    .again
  210. .done    rts
  211.  
  212. ;------------------------------------------------------------------------------
  213. ; PTR TO pathlist=setpathlist(PTR TO process,PTR TO pathlist)
  214. ; if a process, it will get it's pathlist set and return it's old process
  215.  
  216.     xdef    setpathlist__ii
  217. setpathlist__ii
  218.     move.l    8(sp),a0
  219.     move.l    4(sp),a1
  220. setpathlist
  221.     bsr    getcli
  222.     beq.s    .done    ; return 0 if not a process in a0
  223.     move.l    d0,a0
  224.     move.l    cli_CommandDir(a0),d0    ; hold old pathlist
  225.     move.l    a1,d1
  226.     beq.s    .fail            ; ignore install if no newlist
  227.     mkbaddr    d1            ; MKBADDR(newlist)
  228.     move.l    d1,cli_CommandDir(a0)    ; install new list
  229. .fail    baddr    d0            ; return BADDR(oldlist)
  230. .done    rts
  231.